from selenium import webdriver
import time
import OnlineLoans
from selenium.webdriver.common.by import By


class TestOnlineLoans:

    def test_onlineLoans1(self):

        obj = OnlineLoans.onlineLoans('lisi','123456','10000','10')
        driver,text1,text2 = obj[0],obj[1],obj[2]

        index1 = text1.find('条')
        index2 = text2.find('条')
        info1 = text1[:index1]
        info2 = text2[:index2]

        if int(info1) + 1 == int(info2):
            print('通过')
        else:
            print('不通过')

        assert int(info1) + 1 == int(info2)

        driver.quit()

    def test_onlineLoans2(self):

        obj = OnlineLoans.onlineLoans('lisi', '123456', '10000', '10')
        # 银行端操作
        OnlineLoans.onlineLoans_2('admin', '123456')
        driver = obj[0]

        driver.find_element(By.XPATH,'//nav[@class="sidebar-main"]/ul/li[4]/ul/li[3]').click()
        # 点击 银行卡管理
        time.sleep(1)

        text2 = driver.find_element(By.XPATH,"//div[@class='row']/div[not(@class)]/div/div/div[contains(@class,'card-body')]/h4[2]").text
        # 当前默认银行卡的 余额数
        start = text2.find('：')
        end = text2.rfind('元')
        info2 = text2[start+1:end]

        if info2 == '20000.00':
            print('通过')
        else:
            print('不通过')

        assert info2 == '20000.00'

        driver.quit()


    def test_onlineLoans3(self):
        driver = OnlineLoans.onlineLoans_21('lisi5','123456','10000','10')
        time.sleep(1)
        result = driver.find_element(By.XPATH,"//div[@class='jconfirm-content']/div").text

        if result == '申请失败!,请先绑定银行卡':
            print('通过')
        else:
            print('不通过')

        assert result == '申请失败!,请先绑定银行卡'

        driver.quit()


    def test_onlineLoans4(self):
        driver = OnlineLoans.onlineLoans_21('lisi','123456','100000000000000000','10')
        time.sleep(1)
        result = driver.find_element(By.XPATH,"//div[@class='jconfirm-content']/div").text

        if result == '申请失败':
            print('通过')
        else:
            print('不通过')

        assert result == '申请失败'

        driver.quit()


    def test_onlineLoans5(self):

        obj = OnlineLoans.onlineLoans('lisi','123456','10','10')
        driver,text1,text2 = obj[0],obj[1],obj[2]

        index1 = text1.find('条')
        index2 = text2.find('条')
        info1 = text1[:index1]
        info2 = text2[:index2]

        if int(info1) == int(info2):
            print('通过')
        else:
            print('不通过')

        assert int(info1) == int(info2)

        driver.quit()



    def test_onlineLoans6(self):

        obj = OnlineLoans.onlineLoans('lisi','123456','100','366')
        driver,text1,text2 = obj[0],obj[1],obj[2]

        index1 = text1.find('条')
        index2 = text2.find('条')
        info1 = text1[:index1]
        info2 = text2[:index2]

        if int(info1) == int(info2):
            print('通过')
        else:
            print('不通过')

        assert int(info1) == int(info2)

        driver.quit()


    def test_onlineLoans7(self):

        obj = OnlineLoans.onlineLoans('lisi', '123456', '100', '365')
        driver, text1, text2 = obj[0], obj[1], obj[2]

        index1 = text1.find('条')
        index2 = text2.find('条')
        info1 = text1[:index1]
        info2 = text2[:index2]

        if int(info1) + 1 == int(info2):
            print('通过')
        else:
            print('不通过')

        assert int(info1) + 1== int(info2)

        driver.quit()